package com.example.Lezedata.ui.activity.home;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.example.Lezedata.R;
import com.example.Lezedata.ui.activity.baseClass.GBBaseVc;
import com.example.Lezedata.ui.activity.baseClass.GBListViewNoDataBaseAdapter;

import java.util.ArrayList;

public class NewMessageVc extends GBBaseVc {
    @Override
    protected int getLayoutId() {
        return R.layout.activity_new_message_vc;
    }

    @Override
    public CharSequence title() {
        return "Messages";
    }

    ListView listView;
    ArrayList models = new ArrayList();

    GBListViewNoDataBaseAdapter adapter;

    @Override
    protected void viewDidLoad() {
        super.viewDidLoad();
        initView();
        loadData();
    }

    void initView(){
        listView = findViewById(R.id.msg_list);
        adapter = new GBListViewNoDataBaseAdapter(listView) {
            @Override
            public int getCount() {
                return models.size();
            }

            @Override
            public Object getItem(int position) {
                return models.get(position);
            }

            @Override
            public long getItemId(int position) {
                return position;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                if (convertView == null){
                    convertView = LayoutInflater.from(mContext).inflate(R.layout.new_message_cell,parent,false);
                }
                return convertView;
            }
        };
        listView.setAdapter(adapter);
        SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout)listView.getParent();
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Log.d("TAG", "onRefresh: ");
            }
        });
    }

    void loadData(){
        refreshData();
    }

    /// 刷新数据
    void refreshData(){
        adapter.notifyDataSetChanged();
    }
}
